/*
 * @Description: 多辆车弹窗调用的js
 * @Author: yingying.fan
 * @Date: 2019-05-20 18:41:01
 * @Last Modified by: yingying.fan
 * @Last Modified time: 2019-05-22 19:02:42
 */
import BusPop from './BusPop.vue'
import Vue from 'vue'

var BusPopConstructor = Vue.extend(BusPop)

let instance

var show = function(options, parentEl) {
  if (!instance) {
    instance = new BusPopConstructor({
      el: document.createElement('div')
    })
  }
  // 为了每次弹框的时候内容都能修改
  for (var prop in options) {
    if (options.hasOwnProperty(prop)) {
      instance[prop] = options[prop]
    }
  }
  if (parentEl) {
    parentEl.appendChild(instance.$el)
  } else {
    document.body.appendChild(instance.$el)
  }

  instance.show()
}

var hide = function() {
  if (instance) {
    Vue.nextTick(() => {
      instance.hide()
    })
  }
}

var BusPopWindow = {
  show,
  hide
}

export default BusPopWindow
